package com.luzh.myspring.aop;

import com.luzh.myspring.util.ClassUtil;

/**
 * 被代理的对象
 */
public class TargetSource {

    private final Object target;

    public TargetSource(Object target) {
        this.target = target;
    }

    /**
     * 获取真实目标类
     * @return
     */
    public Class<?> getTargetClass(){
        Class<?> clazz = this.target.getClass();
        clazz = ClassUtil.isCglibProxyClass(clazz) ? clazz.getSuperclass() : clazz;
        return clazz;
    }

    /**
     * 获取真实目标接口
     * @return
     */
    public Class<?>[] getInterfaces(){
        return getTargetClass().getInterfaces();
    }

    public Object getTarget(){
        return this.target;
    }

}
